﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    /// <summary>
    /// 数据库表
    /// </summary>
    [Serializable]
    public class Database //: AbsMetaDataContent
    {
        /// <summary>
        /// 数据库主键id
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 数据库标识:TMaster
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 数据库中文名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 数据库展示名称
        /// </summary>
        public string DisplayName { get; set; }

        /// <summary>
        /// 说明
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 是否删除；0:未删除 1:已删除
        /// </summary>
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 是否分库；0:否 1:是
        /// </summary>
        public bool IsSharding { get; set; }

        /// <summary>
        /// 数据库类型：SQLServer;MySQL
        /// </summary>
        public string DbType { get; set; }

        /// <summary>
        /// 字符集:utf-8mb4
        /// </summary>
        public string Charset { get; set; }

        /// <summary>
        /// 项目可见性 0:项目内可见 1:所有人可见
        /// </summary>
        public int Visibility { get; set; }

        /// <summary>
        /// 负责人
        /// </summary>
        public string PersonInCharge { get; set; } 

        /// <summary>
        /// 模块ID
        /// </summary>
        public string ModuleID { get; set; }

        /// <summary>
        /// 关键应用ID
        /// </summary>
        public string AppID { get; set; }

        /// <summary>
        /// 租户id
        /// </summary>
        public string TenantID { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext1 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext2 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext3 { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        //[DataMember]
        public string Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>        
        //[DataMember]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        //[DataMember]
        public string LastModifier { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>        
        //[DataMember]
        public DateTime LastModifyTime { get; set; }

        /// <summary>
        /// 数据库配置
        /// </summary>
        public List<DatabaseConfig> DatabaseConfigs { get; set; }

        /******************************************对接统一元数据管理*******************************************/
        public object Clone()
        {
            var newObject = this.MemberwiseClone() as Database;

            if (DatabaseConfigs != null)
            {
                newObject.DatabaseConfigs = new List<DatabaseConfig>();
                this.DatabaseConfigs.ForEach(i => newObject.DatabaseConfigs.Add(i.Clone() as DatabaseConfig));
            }
            return newObject;
        }     
    }
}
